import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:yqmssa_app/config/app_config.dart';
import 'package:yqmssa_app/router/page_router.dart';
import 'package:yqmssa_app/views/landing/landing_manager.dart';

class SheetScreen extends StatelessWidget {
  const SheetScreen({super.key});

  @override
  Widget build(BuildContext context) {
    final manager = Get.find<LandingManager>();
    return Container(
      padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 24),
      decoration: const BoxDecoration(color: Colors.white, borderRadius: BorderRadius.vertical(top: Radius.circular(8))),
      child: Column(
        mainAxisSize: MainAxisSize.min,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          const Text("您的逾期平台类型", style: TextStyle(fontSize: 18, fontWeight: FontWeight.w500)),
          const SizedBox(height: 24),
          GridView.builder(
            itemCount: manager.rangeType.length,
            shrinkWrap: true,
            physics: const NeverScrollableScrollPhysics(),
            gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
              crossAxisCount: 3,
              childAspectRatio: 3,
              mainAxisSpacing: 12,
              crossAxisSpacing: 16,
            ),
            itemBuilder: (context, index) {
              return InkWell(
                onTap: () {
                  manager.select(type: 1, value: manager.rangeType[index]);
                },
                child: Obx(() {
                  return Container(
                    alignment: Alignment.center,
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(4),
                      gradient:
                          manager.selRangeType.contains(manager.rangeType[index]) ? const LinearGradient(colors: [Color(0XFFF4DDC2), Color(0XFFE4B591)]) : null,
                      border: manager.selRangeType.contains(manager.rangeType[index]) ? null : Border.all(width: 1, color: const Color(0XFFD9D9D9)),
                    ),
                    child: Text(
                      manager.rangeType[index],
                      style: TextStyle(color: manager.selRangeType.contains(manager.rangeType[index]) ? const Color(0XFF4A1C02) : const Color(0XFF666666)),
                    ),
                  );
                }),
              );
            },
          ),
          const SizedBox(height: 16),
          const Text("您的债务逾期金额", style: TextStyle(fontSize: 18, fontWeight: FontWeight.w500)),
          const SizedBox(height: 16),
          GridView.builder(
            itemCount: manager.range.length,
            shrinkWrap: true,
            physics: const NeverScrollableScrollPhysics(),
            gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
              crossAxisCount: 3,
              childAspectRatio: 3,
              mainAxisSpacing: 12,
              crossAxisSpacing: 16,
            ),
            itemBuilder: (context, index) {
              return InkWell(
                onTap: () {
                  manager.select(type: 0, value: manager.range[index]);
                },
                child: Obx(() {
                  return Container(
                    alignment: Alignment.center,
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(4),
                      gradient: manager.selRange.contains(manager.range[index]) ? const LinearGradient(colors: [Color(0XFFF4DDC2), Color(0XFFE4B591)]) : null,
                      border: manager.selRange.contains(manager.range[index]) ? null : Border.all(width: 1, color: const Color(0XFFD9D9D9)),
                    ),
                    child: Text(
                      manager.range[index],
                      style: TextStyle(color: manager.selRange.contains(manager.range[index]) ? const Color(0XFF4A1C02) : const Color(0XFF666666)),
                    ),
                  );
                }),
              );
            },
          ),
          const SizedBox(height: 24),
          GestureDetector(
            onTap: manager.putApply,
            child: Container(
              height: 48,
              decoration: BoxDecoration(
                  color: const Color(0XFFFF6800),
                  borderRadius: BorderRadius.circular(4),
                  gradient: const LinearGradient(colors: [Color(0XFFF4DDC2), Color(0XFFE4B591)])),
              alignment: Alignment.center,
              child: Text(
                (AppConfig.appInitData.channelText?.submitText ?? "").isEmpty ? "立即提交处理" : AppConfig.appInitData.channelText?.submitText ?? "",
                style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: Color(0XFF4A1C02), height: 1),
                overflow: TextOverflow.ellipsis,
              ),
            ),
          ),
          const SizedBox(height: 16),
          Center(
            child: RichText(
              textAlign: TextAlign.center,
              text: TextSpan(style: const TextStyle(color: Color(0XFF666666)), children: [
                TextSpan(text: manager.data.value.fullName),
                WidgetSpan(
                  child: InkWell(
                    onTap: () {
                      Get.toNamed(PageRouter.infoState, parameters: {"html": manager.data.value.statementContent});
                    },
                    child: Text(
                      manager.data.value.statementTitle,
                      style: const TextStyle(color: Colors.black, decoration: TextDecoration.underline),
                    ),
                  ),
                ),
              ]),
            ),
          ),
          const SizedBox(height: 16),
        ],
      ),
    );
  }
}
